<?php   if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function make_title_url($str) 
{
	$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
	$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
	$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
	
	$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
	$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
	$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
	
	$str = preg_replace("/(đ)/", 'd', $str);
	$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
	$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
	
	$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
	$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
	$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
	
	$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
	$str = preg_replace("/(Đ)/", 'D', $str);
	//$str = str_replace(" ", "-", str_replace("&*#39;","",$str));
	
	return $str;
}
function cut_string($str, $len, $more)
{
	if ($str=="" || $str==NULL) return $str;
	if (is_array($str)) return $str;
	$str = trim($str);
	if (strlen($str) <= $len) return $str;
	$str = substr($str,0,$len);
	if ($str != "")
	{
		if (!substr_count($str," "))
		{
	    	if ($more) $str .= " ...";
	        return $str;
	    }
	    while(strlen($str) && ($str[strlen($str)-1] != " "))
		{
	    	$str = substr($str,0,-1);
	    }
	    $str = substr($str,0,-1);
	    //if ($more) $str .= " ...";
	}
	return $str;
	// usage: echo cut_string("welcome to hell",10,1);    ---> output: welcome to ... 
}

 function mb_substrws( $text, $len=200 ) {
          if( (mb_strlen($text) > $len) ) {
     
              $whitespaceposition = mb_strpos($text," ",$len)-1;
     
              if( $whitespaceposition > 0 ) {
                  $chars = count_chars(mb_substr($text, 0, ($whitespaceposition+1)), 1);
                  if ($chars[ord('<')] > $chars[ord('>')])
                      $whitespaceposition = mb_strpos($text,">",$whitespaceposition)-1;
                  $text = mb_substr($text, 0, ($whitespaceposition+1));
              }
     
              // close unclosed html tags
              if( preg_match_all("|<([a-zA-Z]+)|",$text,$aBuffer) ) {
     
                  if( !empty($aBuffer[1]) ) {
     
                      preg_match_all("|</([a-zA-Z]+)>|",$text,$aBuffer2);
     
                      if( count($aBuffer[1]) != count($aBuffer2[1]) ) {
     
                          foreach( $aBuffer[1] as $index => $tag ) {
     
                              if( empty($aBuffer2[1][$index]) || $aBuffer2[1][$index] != $tag)
                                  $text .= '</'.$tag.'>';
                          }
                      }
                  }
              }
          }
          return $text;
      }